package com.itheima.mapper;

import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CheckGroupDao {


    void addCheckGroup(CheckGroup checkGroup);

    void addCheckGroupAndCheckItem(Integer id, Integer[] checkitemIds);


    @Select("SELECT * FROM t_checkgroup WHERE code = #{code} AND name = #{name}")
    CheckGroup findByCodeAndName(String code, String name);

    @Delete("DELETE FROM t_checkgroup_checkitem WHERE checkgroup_id = #{id}")
    void deleteCheckGroupAndCheckItemById(Integer id);

    @Delete("DELETE FROM t_checkgroup WHERE id = #{id}")
    void deleteCheckGroupById(Integer id);

    @Select("SELECT checkgroup_id FROM t_setmeal_checkgroup WHERE setmeal_id = #{setmealId}")
    List<Integer> findCheckGroupIdsBySetmealId(Integer setmealId);

    List<CheckGroup> findPage(int start, int end, String queryString);

    @Select("SELECT COUNT(*) FROM t_checkgroup")
    Long findCount();

    void editCheckGroup(CheckGroup checkGroup);

    @Select("SELECT * FROM t_checkgroup")
    List<CheckGroup> findAll();


    CheckGroup findById(Integer id);

    @Select("SELECT checkitem_id FROM t_checkgroup_checkitem WHERE checkgroup_id = #{id}")
    List<Integer> findCheckItemId(Integer id);

    @Select("SELECT * FROM t_checkitem WHERE id = #{id}")
    CheckItem findCheckItemById(Integer id);
}
